﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class ChangeUser
    {
        private static List<User> users = new List<User>() 
        {
            new User("ioana", "ioanas"),
            new User("roxana", "roxanas"),
            new User("suciu", "sucius")
        };

        public IEnumerable<User> GetUsers(List<string> codes = null)
        {
            if (codes == null)
            {
                return users;
            }

            var result = users.Where(c => codes.Contains(c.UserName));

            return result;
        }

        public void CreateUser(string username, string password)
        {

            User user = new User(username,password);
            foreach (User _user in users)
            {
                try
                {
                    if (_user.UserName != username)
                        users.Add(_user);
                }
                catch { }
            }
        }

        public static  User GetUserByUsername(string username)
        {
            User user = users.FirstOrDefault(p => p.UserName == username);
            if (user != null)
            {
                return user;
            }
            return null;
        }
    }  
}
